/*
 * Copyright 2016 Alibaba Group Holding Limited
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 */
#ifndef LIBPROPERTIES_UTILS_H__
#define LIBPROPERTIES_UTILS_H__

#include <stdbool.h>
#include <string.h>

//#include <log/Log.h>
#define LOG_TAG "libproperties"

extern int __property_debug;

//#define ERROR(format, args...) printf(format, ##args)
//#define WARN(format, args...) printf(format, ##args)
//#define INFO(format, args...) do { if (__property_debug) {printf(format, ##args);} } while(0)
//#define DEBUG(format, args...) do { if (__property_debug) {printf(format, ##args);} } while(0)
//#define ERRNO(format, args...) LOG_E(format" failed, %d, %s.", ##args, errno, strerror(errno))

void log_property_failure(const char *key, const char *value);

static inline bool equal(const char *str1, const char *str2) {
    return !strcmp(str1, str2);
}
static inline bool hasprefix(const char *str, const char *prefix) {
    return !strncmp(str, prefix, strlen(prefix));
}
static inline bool is_persist_prop(const char *key) {
    return hasprefix(key, "persist.");
}
static inline void strncpy_safe(char *dst, size_t dst_size, const char *src) {
    strncpy(dst, src, dst_size);
    dst[dst_size - 1] = 0;
}

#endif
